package com.dingwei.superiordiary.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.dingwei.superiordiary.R;


public class DialogUtil {
    public static final int BUTTON1 = -1;
    public static final int BUTTON2 = -2;
    public static final int WXPAYBUTTON1 = -1;
    public static final int AlipayBUTTON2 = -2;

    public DialogUtil() {
    }

    public static void showAlertDialogChoose(Context context, String title, String content, String leftBtnText, String rightBtnText, final DialogInterface.OnClickListener listener) {
        final AlertDialog dlg = (new AlertDialog.Builder(context)).create();
        dlg.setCanceledOnTouchOutside(false);
        dlg.show();
        Window window = dlg.getWindow();
        window.setContentView(R.layout.dialog_two_button);
        TextView titleTv = (TextView) window.findViewById(R.id.tv_title);
        TextView contentTv = (TextView) window.findViewById(R.id.tv_content);
        Button leftBtn = (Button) window.findViewById(R.id.btn_cancel);
        Button rightBtn = (Button) window.findViewById(R.id.btn_determine);
        leftBtn.setText(leftBtnText);
        rightBtn.setText(rightBtnText);
        titleTv.setText(title);
        contentTv.setText(content);
        leftBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(dlg, BUTTON1);
                }

            }
        });
        rightBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(dlg, BUTTON2);
                }

            }
        });
    }

    public static void showAlertDialogChoose(Context context, String title, String content, final DialogInterface.OnClickListener listener) {
        final AlertDialog dlg = (new AlertDialog.Builder(context)).create();
        dlg.setCanceledOnTouchOutside(false);
        dlg.show();
        Window window = dlg.getWindow();
        window.setContentView(R.layout.dialog_two_button);
        TextView titleTv = (TextView) window.findViewById(R.id.tv_title);
        TextView contentTv = (TextView) window.findViewById(R.id.tv_content);
        Button leftBtn = (Button) window.findViewById(R.id.btn_cancel);
        Button rightBtn = (Button) window.findViewById(R.id.btn_determine);
        titleTv.setText(title);
        contentTv.setText(content);
        leftBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(dlg, BUTTON1);
                }

            }
        });
        rightBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(dlg, BUTTON2);
                }

            }
        });
    }
    public static void showPayDialog(Context context,  final DialogInterface.OnClickListener listener) {
        final AlertDialog dlg = (new AlertDialog.Builder(context)).create();
        dlg.setCanceledOnTouchOutside(false);
        dlg.show();
        Window window = dlg.getWindow();
        window.setContentView(R.layout.dialog_pay);
        SuperButton wxpayBtn = (SuperButton) window.findViewById(R.id.btn_wx_pay);
        SuperButton alipayBtn = (SuperButton) window.findViewById(R.id.btn_alipay);
        TextView tv_cancel = (TextView) window.findViewById(R.id.tv_cancel);
        wxpayBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(dlg, WXPAYBUTTON1);
                }

            }
        });
        alipayBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(dlg, AlipayBUTTON2);
                }

            }
        });
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dlg.dismiss();
            }
        });

    }



}
